var utils = require("../../utils/utils");
var ocrGml = require("../../utils/ocrGml");
var common = require("./common");
var inTask = require("./inTask");
var Action = require("../../base/action");
var actionSearch5 = new Action("search5", {
  execSCount: 0,
  execFCount: 0,
  maxExecSCount: 5,
  maxExecFCount: 5,
  storage: common.storage,
});
actionSearch5.exec = function () {
  var content = "随机搜得金币";
  var ocrItem = ocrGml.findTextOne(
    content,
    true,
    null,
    6,
    (device.height / 10) * 2
  );
  if (ocrItem) {
    var point = utils.getOcrItemPoint(ocrItem);
    var x = point.x;
    var y = point.y;
    for (var index = 0; index < 1; index++) {
      utils.clickXY(x, y);
      sleep(utils.getRandom(3, 5, 1000));
      utils.swipe(1 / 2, 1 / 2, 1 / 4, 1 / 3);
      sleep(utils.getRandom(3, 4, 1000));
      back();
      if (utils.clickTextStartsWith("残忍离开")) {
        console.log("actionSearch5", "找到-残忍离开-");
        sleep(utils.getRandom(2, 3, 1000));
      } else {
        console.log("actionSearch5", "没找到-残忍离开-");
      }
      inTask.run();
    }
    this.execSCount++;
    this.updateStorage();
  } else {
    this.execFCount++;
    this.updateStorage();
    console.log("没有找到" + content);
  }
};
module.exports = actionSearch5;
